package md.lanjing.com.module_wallet.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;



import com.lxh.baselibray.constant.Constant;

import md.lanjing.com.module_wallet.api.WalletApiService;
import md.lanjing.com.module_wallet.bean.ExchangeRequest;
import md.lanjing.com.module_wallet.bean.ExchangeResponce;
import retrofit2.Call;
import retrofit2.Response;

public class ExChangeContact {
    public static class ExChangePresent extends BasePresent<IExChangeView> {
        public void getExchange(final Context context, int number, String dealPwd){
            WalletApiService service= ServiceGenerator.createService(WalletApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            ExchangeRequest request=new ExchangeRequest(userId,number, Md5Utils.stringToMD5(dealPwd));
            service.exChange(request).enqueue(new NetCallBack<ExchangeResponce>() {
                @Override
                public void onSuccess(Call<ExchangeResponce> call, Response<ExchangeResponce> response) {
                    if (getView()!=null){
                        getView().getExChangeData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }
    }

    public interface IExChangeView extends IBaseView {
        void getExChangeData(Response<ExchangeResponce> response);
    }
}
